package com.qk.management.service;

import com.qk.common.storage.FileStorageStrategy;
import com.qk.management.service.decorator.LoggingFileStorageDecorator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;
@Service
public class FileStorageService {

    @Value("${aliyun.oss.endpoint}")
    private String endpoint;
    @Value("${aliyun.oss.bucketName}")
    private String bucketName;
    @Value("${aliyun.oss.accessKeyId:}")
    private String accessKeyId;
    @Value("${aliyun.oss.accessKeySecret:}")
    private String accessKeySecret;
    private final FileStorageStrategy storageStrategy;
    @Autowired
    public FileStorageService(FileStorageFactory factory) {
        FileStorageStrategy baseStrategy = factory.getStrategy("aliyunOSSStorageStrategy");
        this.storageStrategy = new LoggingFileStorageDecorator(baseStrategy);
    }
    public String storeFile(MultipartFile file) throws Exception {
        return storageStrategy.storeFile(file);
    }
    public void deleteFile(String fileUrl) throws Exception {
        storageStrategy.deleteFile(fileUrl);
    }
}